package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-12-05
 * Time: 21:18
 */
public class ThreadDemo7 {
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
           while (true) {
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }

        });
        System.out.println("start 打印之前" + t.isAlive());
        t.start();
        System.out.println("start 打印之后" + t.isAlive());
        Thread.sleep(2000);
        //在两秒之后,t线程已经结束了
        System.out.println("t 结束之后" + t.isAlive());

    }

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() ->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        System.out.println("start 打印之前" + t.isAlive());
        t.start();
        System.out.println("start 打印之后" + t.isAlive());
        //在一秒之后,由于多线程随机调度. isAlove 就不知道状态是什么了.
        Thread.sleep(1000);
    }
}
